fix: stabilize lifecycle and Elixir 1.20 compatibility - #55
fix: stabilize lifecycle and Elixir 1.20 compatibility#55geonwoo-jeong wants to merge 3 commits into
Conversation
bcbf18f to
e1afb48
Compare
Incorrect. this is bind to the react instance it's not going to target another root.
There is a good reason for that. First it come from the other live_vue and live_svelte https://github.com/Valian/live_vue/blob/main/guides/architecture.md?plain=1#L278 |
Contributor checklist
Summary
This draft builds on #54 and adds a small set of production hardening changes without altering its props-diff or streams design:
LiveReact.Encoder.encode/1andencode/2while removing deprecated protocol default arguments on Elixir 1.20Why these changes are needed
React root lifecycle
The previous
destroyed()callback deferred unmounting untilphx:page-loading-stop. That event is tied to page navigation and is not guaranteed when a LiveView patch only removes the component, so the React root and its effects could remain alive after the hook had been destroyed. The deferred callback also read the mutablethis._rootlater, which could target a different root if the hook state changed in the meantime.The hook now captures the current root, clears
this._root, and unmounts immediately. Clearing the reference before unmounting makes repeated or re-entrantdestroyed()calls safe and guarantees that the same root is unmounted exactly once.Protocol callback compatibility
The encoder previously declared
def encode(value, opts \\ [])insidedefprotocol. Elixir 1.20 deprecates default arguments in protocol definitions and warns that protocols may only declare callbacks without an implementation. These warnings fail projects that compile dependencies with warnings treated as errors.The protocol now declares
encode/1andencode/2explicitly. Each implementation definesencode(value)as a direct delegation toencode(value, []), preserving the existing one-argument API and behavior while making both protocol arities explicit and compatible with Elixir 1.20.Validation
phx:page-loading-stopand a repeateddestroyed()callencode(value)toencode(value, [])behavior across its protocol implementationsphoenix_ectoboundary without requiring external provider or network callsFollow-up to #54.